123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941 |
- /**************************************************************************/
- /* test_viewport.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_VIEWPORT_H
- #define TEST_VIEWPORT_H
- #include "scene/2d/physics/area_2d.h"
- #include "scene/2d/physics/collision_shape_2d.h"
- #include "scene/gui/control.h"
- #include "scene/gui/subviewport_container.h"
- #include "scene/main/canvas_layer.h"
- #include "scene/main/window.h"
- #include "scene/resources/2d/rectangle_shape_2d.h"
- #include "servers/physics_server_2d_dummy.h"
- #include "tests/test_macros.h"
- namespace TestViewport {
- class NotificationControlViewport : public Control {
- GDCLASS(NotificationControlViewport, Control);
- protected:
- void _notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_MOUSE_ENTER: {
- if (mouse_over) {
- invalid_order = true;
- }
- mouse_over = true;
- } break;
- case NOTIFICATION_MOUSE_EXIT: {
- if (!mouse_over) {
- invalid_order = true;
- }
- mouse_over = false;
- } break;
- case NOTIFICATION_MOUSE_ENTER_SELF: {
- if (mouse_over_self) {
- invalid_order = true;
- }
- mouse_over_self = true;
- } break;
- case NOTIFICATION_MOUSE_EXIT_SELF: {
- if (!mouse_over_self) {
- invalid_order = true;
- }
- mouse_over_self = false;
- } break;
- }
- }
- public:
- bool mouse_over = false;
- bool mouse_over_self = false;
- bool invalid_order = false;
- };
- // `NotificationControlViewport`-derived class that additionally
- // - allows start Dragging
- // - stores mouse information of last event
- class DragStart : public NotificationControlViewport {
- GDCLASS(DragStart, NotificationControlViewport);
- public:
- MouseButton last_mouse_button;
- Point2i last_mouse_move_position;
- StringName drag_data_name = SNAME("Drag Data");
- virtual Variant get_drag_data(const Point2 &p_point) override {
- return drag_data_name;
- }
- virtual void gui_input(const Ref<InputEvent> &p_event) override {
- Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_valid()) {
- last_mouse_button = mb->get_button_index();
- return;
- }
- Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid()) {
- last_mouse_move_position = mm->get_position();
- return;
- }
- }
- };
- // `NotificationControlViewport`-derived class that acts as a Drag and Drop target.
- class DragTarget : public NotificationControlViewport {
- GDCLASS(DragTarget, NotificationControlViewport);
- protected:
- void _notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_DRAG_BEGIN: {
- during_drag = true;
- } break;
- case NOTIFICATION_DRAG_END: {
- during_drag = false;
- } break;
- }
- }
- public:
- Variant drag_data;
- bool valid_drop = false;
- bool during_drag = false;
- virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override {
- StringName string_data = p_data;
- // Verify drag data is compatible.
- if (string_data != SNAME("Drag Data")) {
- return false;
- }
- // Only the left half is droppable area.
- if (p_point.x * 2 > get_size().x) {
- return false;
- }
- return true;
- }
- virtual void drop_data(const Point2 &p_point, const Variant &p_data) override {
- drag_data = p_data;
- valid_drop = true;
- }
- };
- TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") {
- DragStart *node_a = memnew(DragStart);
- NotificationControlViewport *node_b = memnew(NotificationControlViewport);
- Node2D *node_c = memnew(Node2D);
- DragTarget *node_d = memnew(DragTarget);
- NotificationControlViewport *node_e = memnew(NotificationControlViewport);
- Node *node_f = memnew(Node);
- NotificationControlViewport *node_g = memnew(NotificationControlViewport);
- NotificationControlViewport *node_h = memnew(NotificationControlViewport);
- NotificationControlViewport *node_i = memnew(NotificationControlViewport);
- NotificationControlViewport *node_j = memnew(NotificationControlViewport);
- node_a->set_name(SNAME("NodeA"));
- node_b->set_name(SNAME("NodeB"));
- node_c->set_name(SNAME("NodeC"));
- node_d->set_name(SNAME("NodeD"));
- node_e->set_name(SNAME("NodeE"));
- node_f->set_name(SNAME("NodeF"));
- node_g->set_name(SNAME("NodeG"));
- node_h->set_name(SNAME("NodeH"));
- node_i->set_name(SNAME("NodeI"));
- node_j->set_name(SNAME("NodeJ"));
- node_a->set_position(Point2i(0, 0));
- node_b->set_position(Point2i(10, 10));
- node_c->set_position(Point2i(0, 0));
- node_d->set_position(Point2i(10, 10));
- node_e->set_position(Point2i(10, 100));
- node_g->set_position(Point2i(10, 100));
- node_h->set_position(Point2i(10, 120));
- node_i->set_position(Point2i(2, 0));
- node_j->set_position(Point2i(2, 0));
- node_a->set_size(Point2i(30, 30));
- node_b->set_size(Point2i(30, 30));
- node_d->set_size(Point2i(30, 30));
- node_e->set_size(Point2i(10, 10));
- node_g->set_size(Point2i(10, 10));
- node_h->set_size(Point2i(10, 10));
- node_i->set_size(Point2i(10, 10));
- node_j->set_size(Point2i(10, 10));
- node_a->set_focus_mode(Control::FOCUS_CLICK);
- node_b->set_focus_mode(Control::FOCUS_CLICK);
- node_d->set_focus_mode(Control::FOCUS_CLICK);
- node_e->set_focus_mode(Control::FOCUS_CLICK);
- node_g->set_focus_mode(Control::FOCUS_CLICK);
- node_h->set_focus_mode(Control::FOCUS_CLICK);
- node_i->set_focus_mode(Control::FOCUS_CLICK);
- node_j->set_focus_mode(Control::FOCUS_CLICK);
- Window *root = SceneTree::get_singleton()->get_root();
- DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
- // Scene tree:
- // - root
- // - a (Control)
- // - b (Control)
- // - c (Node2D)
- // - d (Control)
- // - e (Control)
- // - f (Node)
- // - g (Control)
- // - h (Control)
- // - i (Control)
- // - j (Control)
- root->add_child(node_a);
- root->add_child(node_b);
- node_b->add_child(node_c);
- node_c->add_child(node_d);
- root->add_child(node_e);
- node_e->add_child(node_f);
- node_f->add_child(node_g);
- root->add_child(node_h);
- node_h->add_child(node_i);
- node_i->add_child(node_j);
- Point2i on_a = Point2i(5, 5);
- Point2i on_b = Point2i(15, 15);
- Point2i on_d = Point2i(25, 25);
- Point2i on_e = Point2i(15, 105);
- Point2i on_g = Point2i(15, 105);
- Point2i on_i = Point2i(13, 125);
- Point2i on_j = Point2i(15, 125);
- Point2i on_background = Point2i(500, 500);
- Point2i on_outside = Point2i(-1, -1);
- // Unit tests for Viewport::gui_find_control and Viewport::_gui_find_control_at_pos
- SUBCASE("[VIEWPORT][GuiFindControl] Finding Controls at a Viewport-position") {
- // FIXME: It is extremely difficult to create a situation where the Control has a zero determinant.
- // Leaving that if-branch untested.
- SUBCASE("[VIEWPORT][GuiFindControl] Basic position tests") {
- CHECK(root->gui_find_control(on_a) == node_a);
- CHECK(root->gui_find_control(on_b) == node_b);
- CHECK(root->gui_find_control(on_d) == node_d);
- CHECK(root->gui_find_control(on_e) == node_g); // Node F makes G a Root Control at the same position as E
- CHECK(root->gui_find_control(on_g) == node_g);
- CHECK_FALSE(root->gui_find_control(on_background));
- }
- SUBCASE("[VIEWPORT][GuiFindControl] Invisible nodes are not considered as results.") {
- // Non-Root Control
- node_d->hide();
- CHECK(root->gui_find_control(on_d) == node_b);
- // Root Control
- node_b->hide();
- CHECK(root->gui_find_control(on_b) == node_a);
- }
- SUBCASE("[VIEWPORT][GuiFindControl] Root Control with CanvasItem as parent is affected by parent's transform.") {
- node_b->remove_child(node_c);
- node_c->set_position(Point2i(50, 50));
- root->add_child(node_c);
- CHECK(root->gui_find_control(Point2i(65, 65)) == node_d);
- }
- SUBCASE("[VIEWPORT][GuiFindControl] Control Contents Clipping clips accessible position of children.") {
- CHECK_FALSE(node_b->is_clipping_contents());
- CHECK(root->gui_find_control(on_d + Point2i(20, 20)) == node_d);
- node_b->set_clip_contents(true);
- CHECK(root->gui_find_control(on_d) == node_d);
- CHECK_FALSE(root->gui_find_control(on_d + Point2i(20, 20)));
- }
- SUBCASE("[VIEWPORT][GuiFindControl] Top Level Control as descendant of CanvasItem isn't affected by parent's transform.") {
- CHECK(root->gui_find_control(on_d + Point2i(20, 20)) == node_d);
- node_d->set_as_top_level(true);
- CHECK_FALSE(root->gui_find_control(on_d + Point2i(20, 20)));
- CHECK(root->gui_find_control(on_b) == node_d);
- }
- }
- SUBCASE("[Viewport][GuiInputEvent] nullptr as argument doesn't lead to a crash.") {
- ERR_PRINT_OFF;
- root->push_input(nullptr);
- ERR_PRINT_ON;
- }
- // Unit tests for Viewport::_gui_input_event (Mouse Buttons)
- SUBCASE("[Viewport][GuiInputEvent] Mouse Button Down/Up.") {
- SUBCASE("[Viewport][GuiInputEvent] Mouse Button Control Focus Change.") {
- SUBCASE("[Viewport][GuiInputEvent] Grab Focus while no Control has focus.") {
- CHECK_FALSE(root->gui_get_focus_owner());
- // Click on A
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- }
- SUBCASE("[Viewport][GuiInputEvent] Grab Focus from other Control.") {
- node_a->grab_focus();
- CHECK(node_a->has_focus());
- // Click on D
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_d->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- }
- SUBCASE("[Viewport][GuiInputEvent] Non-CanvasItem breaks Transform hierarchy.") {
- CHECK_FALSE(root->gui_get_focus_owner());
- // Click on G absolute coordinates
- SEND_GUI_MOUSE_BUTTON_EVENT(Point2i(15, 105), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_g->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(15, 105), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- }
- SUBCASE("[Viewport][GuiInputEvent] No Focus change when clicking in background.") {
- CHECK_FALSE(root->gui_get_focus_owner());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_get_focus_owner());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- node_a->grab_focus();
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->has_focus());
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Button No Focus Steal while other Mouse Button is pressed.") {
- CHECK_FALSE(root->gui_get_focus_owner());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_b, MouseButton::RIGHT, (int)MouseButtonMask::LEFT | (int)MouseButtonMask::RIGHT, Key::NONE);
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_b, MouseButton::RIGHT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_b, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->has_focus());
- }
- SUBCASE("[Viewport][GuiInputEvent] Allow Focus Steal with LMB while other Mouse Button is held down and was initially pressed without being over a Control.") {
- // TODO: Not sure, if this is intended behavior, but this is an edge case.
- CHECK_FALSE(root->gui_get_focus_owner());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_background, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK_FALSE(root->gui_get_focus_owner());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, (int)MouseButtonMask::LEFT | (int)MouseButtonMask::RIGHT, Key::NONE);
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::RIGHT, Key::NONE);
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_b, MouseButton::LEFT, (int)MouseButtonMask::LEFT | (int)MouseButtonMask::RIGHT, Key::NONE);
- CHECK(node_b->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::RIGHT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_b->has_focus());
- }
- SUBCASE("[Viewport][GuiInputEvent] Ignore Focus from Mouse Buttons when mouse-filter is set to ignore.") {
- node_d->grab_focus();
- node_d->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
- CHECK(node_d->has_focus());
- // Click on overlapping area B&D.
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_b->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- }
- SUBCASE("[Viewport][GuiInputEvent] RMB doesn't grab focus.") {
- node_a->grab_focus();
- CHECK(node_a->has_focus());
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->has_focus());
- }
- SUBCASE("[Viewport][GuiInputEvent] LMB on unfocusable Control doesn't grab focus.") {
- CHECK_FALSE(node_g->has_focus());
- node_g->set_focus_mode(Control::FOCUS_NONE);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_g->has_focus());
- // Now verify the opposite with FOCUS_CLICK
- node_g->set_focus_mode(Control::FOCUS_CLICK);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_g->has_focus());
- node_g->set_focus_mode(Control::FOCUS_CLICK);
- }
- SUBCASE("[Viewport][GuiInputEvent] Signal 'gui_focus_changed' is only emitted if a previously unfocused Control grabs focus.") {
- SIGNAL_WATCH(root, SNAME("gui_focus_changed"));
- Array node_array;
- node_array.push_back(node_a);
- Array signal_args;
- signal_args.push_back(node_array);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- SIGNAL_CHECK(SNAME("gui_focus_changed"), signal_args);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->has_focus());
- SIGNAL_CHECK_FALSE(SNAME("gui_focus_changed"));
- SIGNAL_UNWATCH(root, SNAME("gui_focus_changed"));
- }
- SUBCASE("[Viewport][GuiInputEvent] Focus Propagation to parent items.") {
- SUBCASE("[Viewport][GuiInputEvent] Unfocusable Control with MOUSE_FILTER_PASS propagates focus to parent CanvasItem.") {
- node_d->set_focus_mode(Control::FOCUS_NONE);
- node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d + Point2i(20, 20), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK(node_b->has_focus());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d + Point2i(20, 20), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- // Verify break condition for Root Control.
- node_a->set_focus_mode(Control::FOCUS_NONE);
- node_a->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_b->has_focus());
- }
- SUBCASE("[Viewport][GuiInputEvent] Top Level CanvasItem stops focus propagation.") {
- node_d->set_focus_mode(Control::FOCUS_NONE);
- node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_c->set_as_top_level(true);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_b, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_b, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_get_focus_owner());
- node_d->set_focus_mode(Control::FOCUS_CLICK);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_b, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_b, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_d->has_focus());
- }
- }
- }
- SUBCASE("[Viewport][GuiInputEvent] Process-Mode affects, if GUI Mouse Button Events are processed.") {
- node_a->last_mouse_button = MouseButton::NONE;
- node_a->set_process_mode(Node::PROCESS_MODE_DISABLED);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->last_mouse_button == MouseButton::NONE);
- // Now verify that with allowed processing the event is processed.
- node_a->set_process_mode(Node::PROCESS_MODE_ALWAYS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->last_mouse_button == MouseButton::LEFT);
- }
- }
- // Unit tests for Viewport::_gui_input_event (Mouse Motion)
- SUBCASE("[Viewport][GuiInputEvent] Mouse Motion") {
- // FIXME: Tooltips are not yet tested. They likely require an internal clock.
- SUBCASE("[Viewport][GuiInputEvent] Mouse Motion changes the Control that it is over.") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_a->mouse_over);
- CHECK_FALSE(node_a->mouse_over_self);
- // Move over Control.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->mouse_over);
- CHECK(node_a->mouse_over_self);
- // No change.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(1, 1), MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->mouse_over);
- CHECK(node_a->mouse_over_self);
- // Move over other Control.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_a->mouse_over);
- CHECK_FALSE(node_a->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_d->mouse_over);
- CHECK_FALSE(node_d->mouse_over_self);
- CHECK_FALSE(node_a->invalid_order);
- CHECK_FALSE(node_d->invalid_order);
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation.") {
- node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_g->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK_FALSE(node_d->mouse_over);
- CHECK_FALSE(node_d->mouse_over_self);
- // Move to Control node_d. node_b receives mouse over since it is only separated by a CanvasItem.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK_FALSE(node_d->mouse_over);
- CHECK_FALSE(node_d->mouse_over_self);
- CHECK_FALSE(node_e->mouse_over);
- CHECK_FALSE(node_e->mouse_over_self);
- CHECK_FALSE(node_g->mouse_over);
- CHECK_FALSE(node_g->mouse_over_self);
- // Move to Control node_g. node_g receives mouse over but node_e does not since it is separated by a non-CanvasItem.
- SEND_GUI_MOUSE_MOTION_EVENT(on_g, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_e->mouse_over);
- CHECK_FALSE(node_e->mouse_over_self);
- CHECK(node_g->mouse_over);
- CHECK(node_g->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_e->mouse_over);
- CHECK_FALSE(node_e->mouse_over_self);
- CHECK_FALSE(node_g->mouse_over);
- CHECK_FALSE(node_g->mouse_over_self);
- CHECK_FALSE(node_b->invalid_order);
- CHECK_FALSE(node_d->invalid_order);
- CHECK_FALSE(node_e->invalid_order);
- CHECK_FALSE(node_g->invalid_order);
- node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_g->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation when moving into child.") {
- SIGNAL_WATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_i, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- // Move to Control node_i.
- SEND_GUI_MOUSE_MOTION_EVENT(on_i, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_i->mouse_over);
- CHECK(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Move to child Control node_j. node_i should not receive any new Mouse Enter signals.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Move to parent Control node_i. node_i should not receive any new Mouse Enter signals.
- SEND_GUI_MOUSE_MOTION_EVENT(on_i, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_i->mouse_over);
- CHECK(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK(SceneStringName(mouse_exited), signal_args);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with top level.") {
- node_c->set_as_top_level(true);
- node_i->set_as_top_level(true);
- node_c->set_position(node_b->get_global_position());
- node_i->set_position(node_h->get_global_position());
- node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK_FALSE(node_d->mouse_over);
- CHECK_FALSE(node_d->mouse_over_self);
- // Move to Control node_d. node_b does not receive mouse over since node_c is top level.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK_FALSE(node_d->mouse_over);
- CHECK_FALSE(node_d->mouse_over_self);
- CHECK_FALSE(node_g->mouse_over);
- CHECK_FALSE(node_g->mouse_over_self);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- // Move to Control node_j. node_h does not receive mouse over since node_i is top level.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- CHECK_FALSE(node_b->invalid_order);
- CHECK_FALSE(node_d->invalid_order);
- CHECK_FALSE(node_e->invalid_order);
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_c->set_as_top_level(false);
- node_i->set_as_top_level(false);
- node_c->set_position(Point2i(0, 0));
- node_i->set_position(Point2i(0, 0));
- node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with mouse filter stop.") {
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- // Move to Control node_j. node_h does not receive mouse over since node_i is MOUSE_FILTER_STOP.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification propagation with mouse filter ignore.") {
- node_i->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- // Move to Control node_j. node_i does not receive mouse over since node_i is MOUSE_FILTER_IGNORE.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- // Move to background.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing top level.") {
- SIGNAL_WATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_i, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_d->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to Control node_d.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Change node_c to be top level. node_b should receive Mouse Exit.
- node_c->set_as_top_level(true);
- CHECK_FALSE(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Change node_c to be not top level. node_b should receive Mouse Enter.
- node_c->set_as_top_level(false);
- CHECK(node_b->mouse_over);
- CHECK_FALSE(node_b->mouse_over_self);
- CHECK(node_d->mouse_over);
- CHECK(node_d->mouse_over_self);
- // Move to Control node_j.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_i to top level. node_h should receive Mouse Exit. node_i should not receive any new signals.
- node_i->set_as_top_level(true);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_i to not top level. node_h should receive Mouse Enter. node_i should not receive any new signals.
- node_i->set_as_top_level(false);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- CHECK_FALSE(node_b->invalid_order);
- CHECK_FALSE(node_d->invalid_order);
- CHECK_FALSE(node_e->invalid_order);
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_d->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing the mouse filter to stop.") {
- SIGNAL_WATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_i, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to Control node_j.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_i to MOUSE_FILTER_STOP. node_h should receive Mouse Exit. node_i should not receive any new signals.
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- CHECK_FALSE(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_i to MOUSE_FILTER_PASS. node_h should receive Mouse Enter. node_i should not receive any new signals.
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when changing the mouse filter to ignore.") {
- SIGNAL_WATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_i, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to Control node_j.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_i to MOUSE_FILTER_IGNORE. node_i should receive Mouse Exit.
- node_i->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK(SceneStringName(mouse_exited), signal_args);
- // Change node_i to MOUSE_FILTER_PASS. node_i should receive Mouse Enter.
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_j to MOUSE_FILTER_IGNORE. After updating the mouse motion, node_i should now have mouse_over_self.
- node_j->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Change node_j to MOUSE_FILTER_PASS. After updating the mouse motion, node_j should now have mouse_over_self.
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_i, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when removing the hovered Control.") {
- SIGNAL_WATCH(node_h, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_h, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to Control node_j.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Remove node_i from the tree. node_i and node_j should receive Mouse Exit. node_h should not receive any new signals.
- node_h->remove_child(node_i);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Add node_i to the tree and update the mouse. node_i and node_j should receive Mouse Enter. node_h should not receive any new signals.
- node_h->add_child(node_i);
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_h, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_h, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Mouse Enter/Exit notification when hiding the hovered Control.") {
- SIGNAL_WATCH(node_h, SceneStringName(mouse_entered));
- SIGNAL_WATCH(node_h, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- node_i->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- // Move to Control node_j.
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Hide node_i. node_i and node_j should receive Mouse Exit. node_h should not receive any new signals.
- node_i->hide();
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK_FALSE(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK_FALSE(node_j->mouse_over);
- CHECK_FALSE(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- // Show node_i and update the mouse. node_i and node_j should receive Mouse Enter. node_h should not receive any new signals.
- node_i->show();
- SEND_GUI_MOUSE_MOTION_EVENT(on_j, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_h->mouse_over);
- CHECK_FALSE(node_h->mouse_over_self);
- CHECK(node_i->mouse_over);
- CHECK_FALSE(node_i->mouse_over_self);
- CHECK(node_j->mouse_over);
- CHECK(node_j->mouse_over_self);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- CHECK_FALSE(node_h->invalid_order);
- CHECK_FALSE(node_i->invalid_order);
- CHECK_FALSE(node_j->invalid_order);
- node_i->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_j->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- SIGNAL_UNWATCH(node_h, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(node_h, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Window Mouse Enter/Exit signals.") {
- SIGNAL_WATCH(root, SceneStringName(mouse_entered));
- SIGNAL_WATCH(root, SceneStringName(mouse_exited));
- Array signal_args;
- signal_args.push_back(Array());
- SEND_GUI_MOUSE_MOTION_EVENT(on_outside, MouseButtonMask::NONE, Key::NONE);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK(SceneStringName(mouse_exited), signal_args);
- SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::NONE, Key::NONE);
- SIGNAL_CHECK(SceneStringName(mouse_entered), signal_args);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- SIGNAL_UNWATCH(root, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(root, SceneStringName(mouse_exited));
- }
- SUBCASE("[Viewport][GuiInputEvent] Process-Mode affects, if GUI Mouse Motion Events are processed.") {
- node_a->last_mouse_move_position = on_outside;
- node_a->set_process_mode(Node::PROCESS_MODE_DISABLED);
- SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->last_mouse_move_position == on_outside);
- // Now verify that with allowed processing the event is processed.
- node_a->set_process_mode(Node::PROCESS_MODE_ALWAYS);
- SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_a->last_mouse_move_position == on_a);
- }
- }
- // Unit tests for Viewport::_gui_input_event (Drag and Drop)
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop") {
- // FIXME: Drag-Preview will likely change. Tests for this part would have to be rewritten anyway.
- // See https://github.com/godotengine/godot/pull/67531#issuecomment-1385353430 for details.
- // Note: Testing Drag and Drop with non-embedded windows would require DisplayServerMock additions.
- int min_grab_movement = 11;
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag from one Control to another in the same viewport.") {
- SUBCASE("[Viewport][GuiInputEvent][DnD] Perform successful Drag and Drop on a different Control.") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- // Move above a Control, that is a Drop target and allows dropping at this point.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- CHECK(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK(root->gui_is_drag_successful());
- CHECK((StringName)node_d->drag_data == SNAME("Drag Data"));
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Perform unsuccessful drop on Control.") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- // Move, but don't trigger DnD yet.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(0, min_grab_movement - 1), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- // Move and trigger DnD.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- // Move above a Control, that is not a Drop target.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_FORBIDDEN);
- // Move above a Control, that is a Drop target, but has disallowed this point.
- SEND_GUI_MOUSE_MOTION_EVENT(on_d + Point2i(20, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_FORBIDDEN);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d + Point2i(20, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Perform unsuccessful drop on No-Control.") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- // Move, but don't trigger DnD yet.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement - 1, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- // Move and trigger DnD.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- // Move away from Controls.
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Perform unsuccessful drop outside of window.") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- // Move and trigger DnD.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- // Move outside of window.
- SEND_GUI_MOUSE_MOTION_EVENT(on_outside, MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_outside, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag and Drop doesn't work with other Mouse Buttons than LMB.") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::MIDDLE, MouseButtonMask::MIDDLE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::MIDDLE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::MIDDLE, MouseButtonMask::NONE, Key::NONE);
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag and Drop parent propagation.") {
- Node2D *node_aa = memnew(Node2D);
- Control *node_aaa = memnew(Control);
- Node2D *node_dd = memnew(Node2D);
- Control *node_ddd = memnew(Control);
- node_aaa->set_size(Size2i(10, 10));
- node_aaa->set_position(Point2i(0, 5));
- node_ddd->set_size(Size2i(10, 10));
- node_ddd->set_position(Point2i(0, 5));
- node_a->add_child(node_aa);
- node_aa->add_child(node_aaa);
- node_d->add_child(node_dd);
- node_dd->add_child(node_ddd);
- Point2i on_aaa = on_a + Point2i(-2, 2);
- Point2i on_ddd = on_d + Point2i(-2, 2);
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop propagation to parent Controls.") {
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_ddd->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_aaa, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_aaa + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_ddd, MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_ddd, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK(root->gui_is_drag_successful());
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_ddd->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop grab-propagation stopped by Top Level.") {
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_aaa->set_as_top_level(true);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_aaa, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_aaa + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- node_aaa->set_as_top_level(false);
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop target-propagation stopped by Top Level.") {
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_ddd->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- node_ddd->set_as_top_level(true);
- node_ddd->set_position(Point2i(30, 100));
- SEND_GUI_MOUSE_BUTTON_EVENT(on_aaa, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_aaa + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(Point2i(35, 105), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(Point2i(35, 105), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK_FALSE(root->gui_is_drag_successful());
- node_ddd->set_position(Point2i(0, 5));
- node_ddd->set_as_top_level(false);
- node_aaa->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- node_ddd->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop grab-propagation stopped by non-CanvasItem.") {
- node_g->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_g + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_background, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- node_g->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- SUBCASE("[Viewport][GuiInputEvent] Drag and Drop target-propagation stopped by non-CanvasItem.") {
- node_g->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a - Point2i(1, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE); // Offset for node_aaa.
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(0, min_grab_movement), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_g, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_g, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- node_g->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- }
- memdelete(node_ddd);
- memdelete(node_dd);
- memdelete(node_aaa);
- memdelete(node_aa);
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Force Drag and Drop.") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- node_a->force_drag(SNAME("Drag Data"), nullptr);
- CHECK(root->gui_is_dragging());
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
- // Force Drop doesn't get triggered by mouse Buttons other than LMB.
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE);
- CHECK(root->gui_is_dragging());
- // Force Drop with LMB-Down.
- SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- CHECK_FALSE(root->gui_is_dragging());
- CHECK(root->gui_is_drag_successful());
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- }
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag to a different Viewport.") {
- SubViewportContainer *svc = memnew(SubViewportContainer);
- svc->set_size(Size2(100, 100));
- svc->set_position(Point2(200, 50));
- root->add_child(svc);
- SubViewport *sv = memnew(SubViewport);
- sv->set_embedding_subwindows(true);
- sv->set_size(Size2i(100, 100));
- svc->add_child(sv);
- DragStart *sv_a = memnew(DragStart);
- sv_a->set_position(Point2(10, 10));
- sv_a->set_size(Size2(10, 10));
- sv->add_child(sv_a);
- Point2i on_sva = Point2i(215, 65);
- DragTarget *sv_b = memnew(DragTarget);
- sv_b->set_position(Point2(30, 30));
- sv_b->set_size(Size2(20, 20));
- sv->add_child(sv_b);
- Point2i on_svb = Point2i(235, 85);
- Window *ew = memnew(Window);
- ew->set_position(Point2(50, 200));
- ew->set_size(Size2(100, 100));
- root->add_child(ew);
- DragStart *ew_a = memnew(DragStart);
- ew_a->set_position(Point2(10, 10));
- ew_a->set_size(Size2(10, 10));
- ew->add_child(ew_a);
- Point2i on_ewa = Point2i(65, 215);
- DragTarget *ew_b = memnew(DragTarget);
- ew_b->set_position(Point2(30, 30));
- ew_b->set_size(Size2(20, 20));
- ew->add_child(ew_b);
- Point2i on_ewb = Point2i(85, 235);
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag to SubViewport") {
- sv_b->valid_drop = false;
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- CHECK(sv_b->during_drag);
- SEND_GUI_MOUSE_MOTION_EVENT(on_svb, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_svb, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(sv_b->valid_drop);
- CHECK(!sv_b->during_drag);
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag from SubViewport") {
- node_d->valid_drop = false;
- SEND_GUI_MOUSE_BUTTON_EVENT(on_sva, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_sva + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(sv->gui_is_dragging());
- CHECK(node_d->during_drag);
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_d->valid_drop);
- CHECK(!node_d->during_drag);
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag to embedded Window") {
- ew_b->valid_drop = false;
- SEND_GUI_MOUSE_BUTTON_EVENT(on_a, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_a + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(root->gui_is_dragging());
- CHECK(ew_b->during_drag);
- SEND_GUI_MOUSE_MOTION_EVENT(on_ewb, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_ewb, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(ew_b->valid_drop);
- CHECK(!ew_b->during_drag);
- }
- SUBCASE("[Viewport][GuiInputEvent][DnD] Drag from embedded Window") {
- node_d->valid_drop = false;
- SEND_GUI_MOUSE_BUTTON_EVENT(on_ewa, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_ewa + Point2i(min_grab_movement, 0), MouseButtonMask::LEFT, Key::NONE);
- CHECK(ew->gui_is_dragging());
- CHECK(node_d->during_drag);
- SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::LEFT, Key::NONE);
- CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_CAN_DROP);
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- CHECK(node_d->valid_drop);
- CHECK(!node_d->during_drag);
- }
- memdelete(ew_a);
- memdelete(ew_b);
- memdelete(ew);
- memdelete(sv_a);
- memdelete(sv_b);
- memdelete(sv);
- memdelete(svc);
- }
- }
- memdelete(node_j);
- memdelete(node_i);
- memdelete(node_h);
- memdelete(node_g);
- memdelete(node_f);
- memdelete(node_e);
- memdelete(node_d);
- memdelete(node_c);
- memdelete(node_b);
- 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);
- }
- }
- class TestArea2D : public Area2D {
- GDCLASS(TestArea2D, Area2D);
- void _on_mouse_entered() {
- enter_id = ++TestArea2D::counter; // > 0, if activated.
- }
- void _on_mouse_exited() {
- exit_id = ++TestArea2D::counter; // > 0, if activated.
- }
- void _on_input_event(Node *p_vp, Ref<InputEvent> p_ev, int p_shape) {
- last_input_event = p_ev;
- }
- public:
- static int counter;
- int enter_id = 0;
- int exit_id = 0;
- Ref<InputEvent> last_input_event;
- void init_signals() {
- connect(SceneStringName(mouse_entered), callable_mp(this, &TestArea2D::_on_mouse_entered));
- connect(SceneStringName(mouse_exited), callable_mp(this, &TestArea2D::_on_mouse_exited));
- connect(SceneStringName(input_event), callable_mp(this, &TestArea2D::_on_input_event));
- }
- void test_reset() {
- enter_id = 0;
- exit_id = 0;
- last_input_event.unref();
- }
- };
- int TestArea2D::counter = 0;
- TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") {
- // FIXME: MOUSE_MODE_CAPTURED if-conditions are not testable, because DisplayServerMock doesn't support it.
- // NOTE: This test requires a real physics server.
- PhysicsServer2DDummy *physics_server_2d_dummy = Object::cast_to<PhysicsServer2DDummy>(PhysicsServer2D::get_singleton());
- if (physics_server_2d_dummy) {
- return;
- }
- struct PickingCollider {
- TestArea2D *a;
- CollisionShape2D *c;
- Ref<RectangleShape2D> r;
- };
- SceneTree *tree = SceneTree::get_singleton();
- Window *root = tree->get_root();
- root->set_physics_object_picking(true);
- Point2i on_background = Point2i(800, 800);
- Point2i on_outside = Point2i(-1, -1);
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- Vector<PickingCollider> v;
- for (int i = 0; i < 4; i++) {
- PickingCollider pc;
- pc.a = memnew(TestArea2D);
- pc.c = memnew(CollisionShape2D);
- pc.r.instantiate();
- pc.r->set_size(Size2(150, 150));
- pc.c->set_shape(pc.r);
- pc.a->add_child(pc.c);
- pc.a->set_name("A" + itos(i));
- pc.c->set_name("C" + itos(i));
- v.push_back(pc);
- SIGNAL_WATCH(pc.a, SceneStringName(mouse_entered));
- SIGNAL_WATCH(pc.a, SceneStringName(mouse_exited));
- }
- Node2D *node_a = memnew(Node2D);
- node_a->set_position(Point2i(0, 0));
- v[0].a->set_position(Point2i(0, 0));
- v[1].a->set_position(Point2i(0, 100));
- node_a->add_child(v[0].a);
- node_a->add_child(v[1].a);
- Node2D *node_b = memnew(Node2D);
- node_b->set_position(Point2i(100, 0));
- v[2].a->set_position(Point2i(0, 0));
- v[3].a->set_position(Point2i(0, 100));
- node_b->add_child(v[2].a);
- node_b->add_child(v[3].a);
- root->add_child(node_a);
- root->add_child(node_b);
- Point2i on_all = Point2i(50, 50);
- Point2i on_0 = Point2i(10, 10);
- Point2i on_01 = Point2i(10, 50);
- Point2i on_02 = Point2i(50, 10);
- Array empty_signal_args_2;
- empty_signal_args_2.push_back(Array());
- empty_signal_args_2.push_back(Array());
- Array empty_signal_args_4;
- empty_signal_args_4.push_back(Array());
- empty_signal_args_4.push_back(Array());
- empty_signal_args_4.push_back(Array());
- empty_signal_args_4.push_back(Array());
- for (PickingCollider E : v) {
- E.a->init_signals();
- }
- SUBCASE("[Viewport][Picking2D] Mouse Motion") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_all, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- SIGNAL_CHECK(SceneStringName(mouse_entered), empty_signal_args_4);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_exited));
- for (PickingCollider E : v) {
- CHECK(E.a->enter_id);
- CHECK_FALSE(E.a->exit_id);
- E.a->test_reset();
- }
- SEND_GUI_MOUSE_MOTION_EVENT(on_01, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK(SceneStringName(mouse_exited), empty_signal_args_2);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- if (i < 2) {
- CHECK_FALSE(v[i].a->exit_id);
- } else {
- CHECK(v[i].a->exit_id);
- }
- v[i].a->test_reset();
- }
- SEND_GUI_MOUSE_MOTION_EVENT(on_outside, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- SIGNAL_CHECK_FALSE(SceneStringName(mouse_entered));
- SIGNAL_CHECK(SceneStringName(mouse_exited), empty_signal_args_2);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- if (i < 2) {
- CHECK(v[i].a->exit_id);
- } else {
- CHECK_FALSE(v[i].a->exit_id);
- }
- v[i].a->test_reset();
- }
- }
- SUBCASE("[Viewport][Picking2D] Object moved / passive hovering") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_all, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK(v[i].a->enter_id);
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- node_b->set_position(Point2i(200, 0));
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- if (i < 2) {
- CHECK_FALSE(v[i].a->exit_id);
- } else {
- CHECK(v[i].a->exit_id);
- }
- v[i].a->test_reset();
- }
- node_b->set_position(Point2i(100, 0));
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- if (i < 2) {
- CHECK_FALSE(v[i].a->enter_id);
- } else {
- CHECK(v[i].a->enter_id);
- }
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- }
- SUBCASE("[Viewport][Picking2D] No Processing") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (PickingCollider E : v) {
- E.a->test_reset();
- }
- v[0].a->set_process_mode(Node::PROCESS_MODE_DISABLED);
- v[0].c->set_process_mode(Node::PROCESS_MODE_DISABLED);
- SEND_GUI_MOUSE_MOTION_EVENT(on_02, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- CHECK_FALSE(v[0].a->enter_id);
- CHECK_FALSE(v[0].a->exit_id);
- CHECK(v[2].a->enter_id);
- CHECK_FALSE(v[2].a->exit_id);
- for (PickingCollider E : v) {
- E.a->test_reset();
- }
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- CHECK_FALSE(v[0].a->enter_id);
- CHECK_FALSE(v[0].a->exit_id);
- CHECK_FALSE(v[2].a->enter_id);
- CHECK(v[2].a->exit_id);
- for (PickingCollider E : v) {
- E.a->test_reset();
- }
- v[0].a->set_process_mode(Node::PROCESS_MODE_ALWAYS);
- v[0].c->set_process_mode(Node::PROCESS_MODE_ALWAYS);
- }
- SUBCASE("[Viewport][Picking2D] Multiple events in series") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_0, MouseButtonMask::NONE, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_0 + Point2i(10, 0), MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- if (i < 1) {
- CHECK(v[i].a->enter_id);
- } else {
- CHECK_FALSE(v[i].a->enter_id);
- }
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- SEND_GUI_MOUSE_MOTION_EVENT(on_background + Point2i(10, 10), MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- if (i < 1) {
- CHECK(v[i].a->exit_id);
- } else {
- CHECK_FALSE(v[i].a->exit_id);
- }
- v[i].a->test_reset();
- }
- }
- SUBCASE("[Viewport][Picking2D] Disable Picking") {
- SEND_GUI_MOUSE_MOTION_EVENT(on_02, MouseButtonMask::NONE, Key::NONE);
- root->set_physics_object_picking(false);
- CHECK_FALSE(root->get_physics_object_picking());
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- v[i].a->test_reset();
- }
- root->set_physics_object_picking(true);
- CHECK(root->get_physics_object_picking());
- }
- SUBCASE("[Viewport][Picking2D] CollisionObject in CanvasLayer") {
- CanvasLayer *node_c = memnew(CanvasLayer);
- node_c->set_rotation(Math_PI);
- node_c->set_offset(Point2i(100, 100));
- root->add_child(node_c);
- v[2].a->reparent(node_c, false);
- v[3].a->reparent(node_c, false);
- SEND_GUI_MOUSE_MOTION_EVENT(on_02, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- if (i == 0 || i == 3) {
- CHECK(v[i].a->enter_id);
- } else {
- CHECK_FALSE(v[i].a->enter_id);
- }
- v[i].a->test_reset();
- }
- v[2].a->reparent(node_b, false);
- v[3].a->reparent(node_b, false);
- root->remove_child(node_c);
- memdelete(node_c);
- }
- SUBCASE("[Viewport][Picking2D] Picking Sort") {
- root->set_physics_object_picking_sort(true);
- CHECK(root->get_physics_object_picking_sort());
- SUBCASE("[Viewport][Picking2D] Picking Sort Z-Index") {
- node_a->set_z_index(10);
- v[0].a->set_z_index(0);
- v[1].a->set_z_index(2);
- node_b->set_z_index(5);
- v[2].a->set_z_index(8);
- v[3].a->set_z_index(11);
- v[3].a->set_z_as_relative(false);
- TestArea2D::counter = 0;
- SEND_GUI_MOUSE_MOTION_EVENT(on_all, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- CHECK(v[0].a->enter_id == 4);
- CHECK(v[1].a->enter_id == 2);
- CHECK(v[2].a->enter_id == 1);
- CHECK(v[3].a->enter_id == 3);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- TestArea2D::counter = 0;
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- CHECK(v[0].a->exit_id == 4);
- CHECK(v[1].a->exit_id == 2);
- CHECK(v[2].a->exit_id == 1);
- CHECK(v[3].a->exit_id == 3);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- v[i].a->set_z_as_relative(true);
- v[i].a->set_z_index(0);
- v[i].a->test_reset();
- }
- node_a->set_z_index(0);
- node_b->set_z_index(0);
- }
- SUBCASE("[Viewport][Picking2D] Picking Sort Scene Tree Location") {
- TestArea2D::counter = 0;
- SEND_GUI_MOUSE_MOTION_EVENT(on_all, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK(v[i].a->enter_id == 4 - i);
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- TestArea2D::counter = 0;
- SEND_GUI_MOUSE_MOTION_EVENT(on_background, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- CHECK(v[i].a->exit_id == 4 - i);
- v[i].a->test_reset();
- }
- }
- root->set_physics_object_picking_sort(false);
- CHECK_FALSE(root->get_physics_object_picking_sort());
- }
- SUBCASE("[Viewport][Picking2D] Mouse Button") {
- SEND_GUI_MOUSE_BUTTON_EVENT(on_0, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- if (i == 0) {
- CHECK(v[i].a->enter_id);
- } else {
- CHECK_FALSE(v[i].a->enter_id);
- }
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_0, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- CHECK_FALSE(v[i].a->enter_id);
- CHECK_FALSE(v[i].a->exit_id);
- v[i].a->test_reset();
- }
- }
- SUBCASE("[Viewport][Picking2D] Screen Touch") {
- SEND_GUI_TOUCH_EVENT(on_01, true, false);
- tree->physics_process(1);
- for (int i = 0; i < v.size(); i++) {
- if (i < 2) {
- Ref<InputEventScreenTouch> st = v[i].a->last_input_event;
- CHECK(st.is_valid());
- } else {
- CHECK(v[i].a->last_input_event.is_null());
- }
- v[i].a->test_reset();
- }
- }
- for (PickingCollider E : v) {
- SIGNAL_UNWATCH(E.a, SceneStringName(mouse_entered));
- SIGNAL_UNWATCH(E.a, SceneStringName(mouse_exited));
- memdelete(E.c);
- memdelete(E.a);
- }
- }
- TEST_CASE("[SceneTree][Viewport] Embedded Windows") {
- Window *root = SceneTree::get_singleton()->get_root();
- Window *w = memnew(Window);
- SUBCASE("[Viewport] Safe-rect of embedded Window") {
- root->add_child(w);
- root->subwindow_set_popup_safe_rect(w, Rect2i(10, 10, 10, 10));
- CHECK_EQ(root->subwindow_get_popup_safe_rect(w), Rect2i(10, 10, 10, 10));
- root->remove_child(w);
- CHECK_EQ(root->subwindow_get_popup_safe_rect(w), Rect2i());
- }
- memdelete(w);
- }
- } // namespace TestViewport
- #endif // TEST_VIEWPORT_H
|