You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
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
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user