diff options
author | kleonc <9283098+kleonc@users.noreply.github.com> | 2024-03-15 04:19:44 +0100 |
---|---|---|
committer | kleonc <9283098+kleonc@users.noreply.github.com> | 2024-03-15 04:19:52 +0100 |
commit | f08e782916b01fd05497db7deed73c5701308ec6 (patch) | |
tree | 136b20d74b4a28c42af92ca052e9bc401631c3c4 /scene/gui/control.cpp | |
parent | 0175be8948d68cf90c55ce08e8e5bf46ea29ce40 (diff) | |
download | redot-engine-f08e782916b01fd05497db7deed73c5701308ec6.tar.gz |
Fix Control::set_global_position for rotated/scaled transforms
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r-- | scene/gui/control.cpp | 14 |
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 { |