Merge pull request #80105 from Sauermann/fix-global-transform
Fix global transform validity for `Node2D` and `Control`
This commit is contained in:
commit
2c0a74a149
|
@ -138,10 +138,6 @@ void Node2D::_update_transform() {
|
|||
|
||||
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), transform);
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_notify_transform();
|
||||
}
|
||||
|
||||
|
@ -378,10 +374,6 @@ void Node2D::set_transform(const Transform2D &p_transform) {
|
|||
|
||||
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), transform);
|
||||
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_notify_transform();
|
||||
}
|
||||
|
||||
|
|
|
@ -1734,6 +1734,10 @@ void Control::_size_changed() {
|
|||
if (pos_changed && !size_changed) {
|
||||
_update_canvas_item_transform(); //move because it won't be updated
|
||||
}
|
||||
} else {
|
||||
if (pos_changed) {
|
||||
_notify_transform();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -320,7 +320,6 @@ void CanvasItem::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
_set_global_invalid(true);
|
||||
_enter_canvas();
|
||||
|
||||
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, is_visible_in_tree()); // The visibility of the parent may change.
|
||||
|
@ -367,7 +366,11 @@ void CanvasItem::_notification(int p_what) {
|
|||
case NOTIFICATION_WORLD_2D_CHANGED: {
|
||||
_exit_canvas();
|
||||
_enter_canvas();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_PARENTED: {
|
||||
// The node is not inside the tree during this notification.
|
||||
_notify_transform();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,11 +152,8 @@ private:
|
|||
|
||||
protected:
|
||||
_FORCE_INLINE_ void _notify_transform() {
|
||||
if (!is_inside_tree()) {
|
||||
return;
|
||||
}
|
||||
_notify_transform(this);
|
||||
if (!block_transform_notify && notify_local_transform) {
|
||||
if (is_inside_tree() && !block_transform_notify && notify_local_transform) {
|
||||
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**************************************************************************/
|
||||
/* test_control.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_CONTROL_H
|
||||
#define TEST_CONTROL_H
|
||||
|
||||
#include "scene/gui/control.h"
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
namespace TestControl {
|
||||
|
||||
TEST_CASE("[SceneTree][Control]") {
|
||||
SUBCASE("[Control][Global Transform] Global Transform should be accessible while not in SceneTree.") { // GH-79453
|
||||
Control *test_node = memnew(Control);
|
||||
Control *test_child = memnew(Control);
|
||||
test_node->add_child(test_child);
|
||||
|
||||
test_node->set_global_position(Point2(1, 1));
|
||||
CHECK_EQ(test_node->get_global_position(), Point2(1, 1));
|
||||
CHECK_EQ(test_child->get_global_position(), Point2(1, 1));
|
||||
test_node->set_global_position(Point2(2, 2));
|
||||
CHECK_EQ(test_node->get_global_position(), Point2(2, 2));
|
||||
test_node->set_scale(Vector2(4, 4));
|
||||
CHECK_EQ(test_node->get_global_transform(), Transform2D(0, Size2(4, 4), 0, Vector2(2, 2)));
|
||||
test_node->set_scale(Vector2(1, 1));
|
||||
test_node->set_rotation_degrees(90);
|
||||
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(2, 2)));
|
||||
test_node->set_pivot_offset(Vector2(1, 0));
|
||||
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(3, 1)));
|
||||
|
||||
memdelete(test_child);
|
||||
memdelete(test_node);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace TestControl
|
||||
|
||||
#endif // TEST_CONTROL_H
|
|
@ -0,0 +1,63 @@
|
|||
/**************************************************************************/
|
||||
/* test_node_2d.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_NODE_2D_H
|
||||
#define TEST_NODE_2D_H
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
#include "tests/test_macros.h"
|
||||
|
||||
namespace TestNode2D {
|
||||
|
||||
TEST_CASE("[SceneTree][Node2D]") {
|
||||
SUBCASE("[Node2D][Global Transform] Global Transform should be accessible while not in SceneTree.") { // GH-79453
|
||||
Node2D *test_node = memnew(Node2D);
|
||||
test_node->set_name("node");
|
||||
Node2D *test_child = memnew(Node2D);
|
||||
test_child->set_name("child");
|
||||
test_node->add_child(test_child);
|
||||
|
||||
test_node->set_global_position(Point2(1, 1));
|
||||
CHECK_EQ(test_node->get_global_position(), Point2(1, 1));
|
||||
CHECK_EQ(test_child->get_global_position(), Point2(1, 1));
|
||||
test_node->set_global_position(Point2(2, 2));
|
||||
CHECK_EQ(test_node->get_global_position(), Point2(2, 2));
|
||||
test_node->set_global_transform(Transform2D(0, Point2(3, 3)));
|
||||
CHECK_EQ(test_node->get_global_position(), Point2(3, 3));
|
||||
|
||||
memdelete(test_child);
|
||||
memdelete(test_node);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace TestNode2D
|
||||
|
||||
#endif // TEST_NODE_2D_H
|
|
@ -95,6 +95,7 @@
|
|||
#include "tests/scene/test_bit_map.h"
|
||||
#include "tests/scene/test_code_edit.h"
|
||||
#include "tests/scene/test_color_picker.h"
|
||||
#include "tests/scene/test_control.h"
|
||||
#include "tests/scene/test_curve.h"
|
||||
#include "tests/scene/test_curve_2d.h"
|
||||
#include "tests/scene/test_curve_3d.h"
|
||||
|
@ -106,6 +107,7 @@
|
|||
#include "tests/scene/test_navigation_region_2d.h"
|
||||
#include "tests/scene/test_navigation_region_3d.h"
|
||||
#include "tests/scene/test_node.h"
|
||||
#include "tests/scene/test_node_2d.h"
|
||||
#include "tests/scene/test_packed_scene.h"
|
||||
#include "tests/scene/test_path_2d.h"
|
||||
#include "tests/scene/test_path_3d.h"
|
||||
|
|
Loading…
Reference in New Issue