Merge pull request #71768 from Sauermann/fix-vp-mouse-position
Fix Viewport::get_mouse_position for SubViewports
This commit is contained in:
commit
7ebd8b502d
@ -1172,11 +1172,16 @@ Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Viewport::get_mouse_position() const {
|
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) {
|
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);
|
Vector2 gpos = xform.xform(p_position);
|
||||||
Input::get_singleton()->warp_mouse(gpos);
|
Input::get_singleton()->warp_mouse(gpos);
|
||||||
}
|
}
|
||||||
@ -3288,6 +3293,10 @@ Viewport::SDFScale Viewport::get_sdf_scale() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Viewport::get_screen_transform() 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();
|
return get_final_transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4226,14 +4235,14 @@ DisplayServer::WindowID SubViewport::get_window_id() const {
|
|||||||
return DisplayServer::INVALID_WINDOW_ID;
|
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;
|
Transform2D container_transform;
|
||||||
SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
|
SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
|
||||||
if (c) {
|
if (c) {
|
||||||
if (c->is_stretch_enabled()) {
|
if (c->is_stretch_enabled()) {
|
||||||
container_transform.scale(Vector2(c->get_stretch_shrink(), c->get_stretch_shrink()));
|
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 {
|
} else {
|
||||||
WARN_PRINT_ONCE("SubViewport is not a child of a SubViewportContainer. get_screen_transform doesn't return the actual screen position.");
|
WARN_PRINT_ONCE("SubViewport is not a child of a SubViewportContainer. get_screen_transform doesn't return the actual screen position.");
|
||||||
}
|
}
|
||||||
|
@ -651,7 +651,8 @@ public:
|
|||||||
|
|
||||||
virtual bool is_size_2d_override_stretch_enabled() const { return true; }
|
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(); }
|
virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
|
||||||
|
|
||||||
#ifndef _3D_DISABLED
|
#ifndef _3D_DISABLED
|
||||||
@ -780,7 +781,7 @@ public:
|
|||||||
void set_clear_mode(ClearMode p_mode);
|
void set_clear_mode(ClearMode p_mode);
|
||||||
ClearMode get_clear_mode() const;
|
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;
|
virtual Transform2D get_popup_base_transform() const override;
|
||||||
|
|
||||||
SubViewport();
|
SubViewport();
|
||||||
|
@ -2120,11 +2120,13 @@ Transform2D Window::get_final_transform() const {
|
|||||||
return window_transform * stretch_transform * global_canvas_transform;
|
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;
|
Transform2D embedder_transform;
|
||||||
if (_get_embedder()) {
|
if (_get_embedder()) {
|
||||||
embedder_transform.translate_local(get_position());
|
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();
|
return embedder_transform * get_final_transform();
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ public:
|
|||||||
//
|
//
|
||||||
|
|
||||||
virtual Transform2D get_final_transform() const override;
|
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;
|
virtual Transform2D get_popup_base_transform() const override;
|
||||||
|
|
||||||
Rect2i get_parent_rect() const;
|
Rect2i get_parent_rect() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user