summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/viewport.cpp17
-rw-r--r--scene/main/viewport.h5
-rw-r--r--scene/main/window.cpp6
-rw-r--r--scene/main/window.h2
4 files changed, 21 insertions, 9 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 25499d4a2b..89f0fd2039 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1172,11 +1172,16 @@ Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
}
Vector2 Viewport::get_mouse_position() const {
- return gui.last_mouse_pos;
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_MOUSE)) {
+ return get_screen_transform_internal(true).affine_inverse().xform(DisplayServer::get_singleton()->mouse_get_position());
+ } else {
+ // Fallback to Input for getting mouse position in case of emulated mouse.
+ return get_screen_transform_internal().affine_inverse().xform(Input::get_singleton()->get_mouse_position());
+ }
}
void Viewport::warp_mouse(const Vector2 &p_position) {
- Transform2D xform = get_screen_transform();
+ Transform2D xform = get_screen_transform_internal();
Vector2 gpos = xform.xform(p_position);
Input::get_singleton()->warp_mouse(gpos);
}
@@ -3288,6 +3293,10 @@ Viewport::SDFScale Viewport::get_sdf_scale() const {
}
Transform2D Viewport::get_screen_transform() const {
+ return get_screen_transform_internal();
+}
+
+Transform2D Viewport::get_screen_transform_internal(bool p_absolute_position) const {
return get_final_transform();
}
@@ -4226,14 +4235,14 @@ DisplayServer::WindowID SubViewport::get_window_id() const {
return DisplayServer::INVALID_WINDOW_ID;
}
-Transform2D SubViewport::get_screen_transform() const {
+Transform2D SubViewport::get_screen_transform_internal(bool p_absolute_position) const {
Transform2D container_transform;
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;
+ container_transform = c->get_viewport()->get_screen_transform_internal(p_absolute_position) * 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.");
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 4144eaabb9..055fad5369 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -651,7 +651,8 @@ public:
virtual bool is_size_2d_override_stretch_enabled() const { return true; }
- virtual Transform2D get_screen_transform() const;
+ Transform2D get_screen_transform() const;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const;
virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
#ifndef _3D_DISABLED
@@ -780,7 +781,7 @@ public:
void set_clear_mode(ClearMode p_mode);
ClearMode get_clear_mode() const;
- virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
SubViewport();
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 9fcfb29ef7..4cdd447235 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -2120,11 +2120,13 @@ Transform2D Window::get_final_transform() const {
return window_transform * stretch_transform * global_canvas_transform;
}
-Transform2D Window::get_screen_transform() const {
+Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const {
Transform2D embedder_transform;
if (_get_embedder()) {
embedder_transform.translate_local(get_position());
- embedder_transform = _get_embedder()->get_screen_transform() * embedder_transform;
+ embedder_transform = _get_embedder()->get_screen_transform_internal(p_absolute_position) * embedder_transform;
+ } else if (p_absolute_position) {
+ embedder_transform.translate_local(get_position());
}
return embedder_transform * get_final_transform();
}
diff --git a/scene/main/window.h b/scene/main/window.h
index 9861fefc68..1920aae0fe 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -377,7 +377,7 @@ public:
//
virtual Transform2D get_final_transform() const override;
- virtual Transform2D get_screen_transform() const override;
+ virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
Rect2i get_parent_rect() const;