summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/main/viewport.cpp21
-rw-r--r--scene/main/viewport.h4
-rw-r--r--scene/main/window.cpp9
-rw-r--r--scene/main/window.h2
4 files changed, 35 insertions, 1 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 20cb0176e0..e50197d5fa 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1125,7 +1125,8 @@ Vector2 Viewport::get_mouse_position() const {
}
void Viewport::warp_mouse(const Vector2 &p_position) {
- Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_position);
+ Transform2D xform = get_screen_transform();
+ Vector2 gpos = xform.xform(p_position).round();
Input::get_singleton()->warp_mouse(gpos);
}
@@ -3113,6 +3114,10 @@ Viewport::SDFScale Viewport::get_sdf_scale() const {
return sdf_scale;
}
+Transform2D Viewport::get_screen_transform() const {
+ return _get_input_pre_xform().affine_inverse() * get_final_transform();
+}
+
#ifndef _3D_DISABLED
AudioListener3D *Viewport::get_audio_listener_3d() const {
return audio_listener_3d;
@@ -3971,6 +3976,20 @@ Transform2D SubViewport::_stretch_transform() {
return transform;
}
+Transform2D SubViewport::get_screen_transform() const {
+ Transform2D container_transform = Transform2D();
+ SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
+ if (c) {
+ if (c->is_stretch_enabled()) {
+ container_transform.scale(Vector2(c->get_stretch_shrink(), c->get_stretch_shrink()));
+ }
+ container_transform = c->get_viewport()->get_screen_transform() * c->get_global_transform_with_canvas() * container_transform;
+ } else {
+ WARN_PRINT_ONCE("SubViewport is not a child of a SubViewportContainer. get_screen_transform doesn't return the actual screen position.");
+ }
+ return 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 d5fca1b881..80be53fab8 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -609,6 +609,8 @@ public:
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
+ virtual Transform2D get_screen_transform() const;
+
#ifndef _3D_DISABLED
bool use_xr = false;
friend class AudioListener3D;
@@ -732,6 +734,8 @@ public:
void set_clear_mode(ClearMode p_mode);
ClearMode get_clear_mode() const;
+ virtual Transform2D get_screen_transform() const override;
+
SubViewport();
~SubViewport();
};
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 62e8e7fea7..2faa107fb4 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1460,6 +1460,15 @@ void Window::_validate_property(PropertyInfo &property) const {
}
}
+Transform2D Window::get_screen_transform() const {
+ Transform2D embedder_transform = Transform2D();
+ if (_get_embedder()) {
+ embedder_transform.translate(get_position());
+ embedder_transform = _get_embedder()->get_screen_transform() * embedder_transform;
+ }
+ return embedder_transform * Viewport::get_screen_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 3d8e337b4a..f674f6425a 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -291,6 +291,8 @@ public:
Ref<Font> get_theme_default_font() const;
int get_theme_default_font_size() const;
+ virtual Transform2D get_screen_transform() const override;
+
Rect2i get_parent_rect() const;
virtual DisplayServer::WindowID get_window_id() const override;