summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-31 15:57:07 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-31 15:57:07 +0100
commit1c42e141d0ec3c09346b1003a5b31301bace030a (patch)
tree50a898bf38b6817ad83d6fbf48c000b37691f29a
parentcf2bf08b4160c5c02853086284b7a69bb357a2a2 (diff)
parent2bf2217b1a0695db73e1b770353c3e1c4580dfd7 (diff)
Merge pull request #59310 from Sauermann/proposal-event-transform
Calculate window input event transform only on window change
-rw-r--r--scene/main/viewport.cpp11
-rw-r--r--scene/main/window.cpp8
-rw-r--r--scene/main/window.h2
3 files changed, 14 insertions, 7 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 48cff5aa8e..64bd3fe2c1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1110,14 +1110,11 @@ Viewport::PositionalShadowAtlasQuadrantSubdiv Viewport::get_positional_shadow_at
}
Transform2D Viewport::_get_input_pre_xform() const {
- Transform2D pre_xf;
-
- if (to_screen_rect.size.x != 0 && to_screen_rect.size.y != 0) {
- pre_xf.columns[2] = -to_screen_rect.position;
- pre_xf.scale(Vector2(size) / to_screen_rect.size);
+ const Window *this_window = Object::cast_to<Window>(this);
+ if (this_window) {
+ return this_window->window_transform.affine_inverse();
}
-
- return pre_xf;
+ return Transform2D();
}
Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 869d12b4df..1f629aaf94 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -907,6 +907,7 @@ void Window::_update_viewport_size() {
Rect2i attach_to_screen_rect(Point2i(), size);
Transform2D stretch_transform_new;
float font_oversampling = 1.0;
+ window_transform = Transform2D();
if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
font_oversampling = content_scale_factor;
@@ -993,11 +994,18 @@ void Window::_update_viewport_size() {
Size2 scale = Vector2(screen_size) / Vector2(final_size_override);
stretch_transform_new.scale(scale);
+ window_transform.translate_local(margin);
} break;
case CONTENT_SCALE_MODE_VIEWPORT: {
final_size = (viewport_size / content_scale_factor).floor();
attach_to_screen_rect = Rect2(margin, screen_size);
+ window_transform.translate_local(margin);
+ if (final_size.x != 0 && final_size.y != 0) {
+ Transform2D scale_transform;
+ scale_transform.scale(Vector2(attach_to_screen_rect.size) / Vector2(final_size));
+ window_transform *= scale_transform;
+ }
} break;
}
}
diff --git a/scene/main/window.h b/scene/main/window.h
index 182caf5f0c..1730de0b33 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -173,6 +173,8 @@ private:
Viewport *embedder = nullptr;
+ Transform2D window_transform;
+
friend class Viewport; //friend back, can call the methods below
void _window_input(const Ref<InputEvent> &p_ev);