summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2022-10-01 04:31:52 +0200
committerMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2022-10-22 01:47:52 +0200
commit99bb7ab6922b4490cfe17d5f3b1a269c0b9851a5 (patch)
tree1d3fbb421e7b2a8d376adbb6a777a75064b70a4d /scene
parentefd2a8ac235ef8c1f75aa38985347f6aac238afb (diff)
Fix Control rect coordinate system inconsistency
Fix get_rect, get_global_rect and get_screen_rect to take Controls scale into account. Simplify get_screen_position and get_screen_rect
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/control.cpp24
1 files changed, 7 insertions, 17 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 064c4b597f..46777ff62b 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1360,13 +1360,7 @@ Point2 Control::get_global_position() const {
Point2 Control::get_screen_position() const {
ERR_FAIL_COND_V(!is_inside_tree(), Point2());
- Point2 global_pos = get_global_transform_with_canvas().get_origin();
- Window *w = Object::cast_to<Window>(get_viewport());
- if (w && !w->is_embedding_subwindows()) {
- global_pos += w->get_position();
- }
-
- return global_pos;
+ return get_screen_transform().get_origin();
}
void Control::_set_size(const Size2 &p_size) {
@@ -1416,24 +1410,20 @@ void Control::set_rect(const Rect2 &p_rect) {
}
Rect2 Control::get_rect() const {
- return Rect2(get_position(), get_size());
+ Transform2D xform = get_transform();
+ return Rect2(xform.get_origin(), xform.get_scale() * get_size());
}
Rect2 Control::get_global_rect() const {
- return Rect2(get_global_position(), get_size());
+ Transform2D xform = get_global_transform();
+ return Rect2(xform.get_origin(), xform.get_scale() * get_size());
}
Rect2 Control::get_screen_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
- Rect2 r(get_global_position(), get_size());
-
- Window *w = Object::cast_to<Window>(get_viewport());
- if (w && !w->is_embedding_subwindows()) {
- r.position += w->get_position();
- }
-
- return r;
+ Transform2D xform = get_screen_transform();
+ return Rect2(xform.get_origin(), xform.get_scale() * get_size());
}
Rect2 Control::get_window_rect() const {