summaryrefslogtreecommitdiffstats
path: root/scene/gui/control.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r--scene/gui/control.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 974ecd1edc..d65399446c 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1406,15 +1406,11 @@ void Control::_set_global_position(const Point2 &p_point) {
void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) {
ERR_MAIN_THREAD_GUARD;
-
- Transform2D global_transform_cache = get_global_transform();
- if (p_point == global_transform_cache.get_origin()) {
- return; // Edge case, but avoids calculation.
- }
-
- Point2 internal_position = global_transform_cache.affine_inverse().xform(p_point);
-
- set_position(internal_position + data.pos_cache, p_keep_offsets);
+ // (parent_global_transform * T(new_position) * internal_transform).origin == new_global_position
+ // (T(new_position) * internal_transform).origin == new_position_in_parent_space
+ // new_position == new_position_in_parent_space - internal_transform.origin
+ Point2 position_in_parent_space = data.parent_canvas_item ? data.parent_canvas_item->get_global_transform().affine_inverse().xform(p_point) : p_point;
+ set_position(position_in_parent_space - _get_internal_transform().get_origin(), p_keep_offsets);
}
Point2 Control::get_global_position() const {