summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-26 16:00:14 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-26 16:00:14 +0100
commit13e20fed9947c70ab08644be9ba74ac2a4329a1f (patch)
tree442e4867eb336862abde7f7334cbb486ef113f4c /scene
parent296dea77fe9a7a438e3c127899537fa9b75c1050 (diff)
parentc4ed247f5f49eeda614290bf8e0b61df9a6f089e (diff)
Merge pull request #68627 from Sauermann/fix-tooltip-position
Fix position of Tooltips
Diffstat (limited to 'scene')
-rw-r--r--scene/main/canvas_item.cpp12
-rw-r--r--scene/main/viewport.cpp15
-rw-r--r--scene/main/viewport.h2
-rw-r--r--scene/main/window.cpp13
-rw-r--r--scene/main/window.h1
5 files changed, 32 insertions, 11 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 7b0554442c..3323c0f848 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -154,17 +154,7 @@ Transform2D CanvasItem::get_global_transform_with_canvas() const {
Transform2D CanvasItem::get_screen_transform() const {
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
- Transform2D xform = get_global_transform_with_canvas();
-
- Window *w = Object::cast_to<Window>(get_viewport());
- if (w && !w->is_embedding_subwindows()) {
- Transform2D s;
- s.set_origin(w->get_position());
-
- xform = s * xform;
- }
-
- return xform;
+ return get_viewport()->get_popup_base_transform() * get_global_transform_with_canvas();
}
Transform2D CanvasItem::get_global_transform() const {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index d15a66478d..fcecbc717a 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -4186,6 +4186,21 @@ Transform2D SubViewport::get_screen_transform() const {
return container_transform * Viewport::get_screen_transform();
}
+Transform2D SubViewport::get_popup_base_transform() const {
+ if (is_embedding_subwindows()) {
+ return Transform2D();
+ }
+ SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
+ if (!c) {
+ return Viewport::get_screen_transform();
+ }
+ Transform2D container_transform;
+ if (c->is_stretch_enabled()) {
+ container_transform.scale(Vector2(c->get_stretch_shrink(), c->get_stretch_shrink()));
+ }
+ return c->get_screen_transform() * container_transform * Viewport::get_screen_transform();
+}
+
void SubViewport::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 603e92b071..d5d5201e9a 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -649,6 +649,7 @@ public:
bool get_canvas_cull_mask_bit(uint32_t p_layer) const;
virtual Transform2D get_screen_transform() const;
+ virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
#ifndef _3D_DISABLED
bool use_xr = false;
@@ -775,6 +776,7 @@ public:
ClearMode get_clear_mode() const;
virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_popup_base_transform() const override;
SubViewport();
~SubViewport();
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 2c6599d849..3ceb27b3e6 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -2104,6 +2104,19 @@ Transform2D Window::get_screen_transform() const {
return embedder_transform * Viewport::get_screen_transform();
}
+Transform2D Window::get_popup_base_transform() const {
+ if (is_embedding_subwindows()) {
+ return Transform2D();
+ }
+ Transform2D window_transform;
+ window_transform.set_origin(get_position());
+ window_transform *= Viewport::get_screen_transform();
+ if (_get_embedder()) {
+ return _get_embedder()->get_popup_base_transform() * window_transform;
+ }
+ return window_transform;
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
diff --git a/scene/main/window.h b/scene/main/window.h
index e9c217f973..18841a4f1a 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -373,6 +373,7 @@ public:
//
virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_popup_base_transform() const override;
Rect2i get_parent_rect() const;
virtual DisplayServer::WindowID get_window_id() const override;