summaryrefslogtreecommitdiff
path: root/scene/main/viewport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r--scene/main/viewport.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0e32fd006d..c13b4eb060 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -764,13 +764,30 @@ bool Viewport::get_render_target_vflip() const{
}
+Matrix32 Viewport::_get_input_pre_xform() const {
+
+ Matrix32 pre_xf;
+ if (render_target) {
+
+ ERR_FAIL_COND_V(to_screen_rect.size.x==0,pre_xf);
+ ERR_FAIL_COND_V(to_screen_rect.size.y==0,pre_xf);
+ pre_xf.scale(rect.size/to_screen_rect.size);
+ pre_xf.elements[2]=-to_screen_rect.pos;
+ } else {
+
+ pre_xf.elements[2]=-rect.pos;
+ }
+
+ return pre_xf;
+}
+
void Viewport::_make_input_local(InputEvent& ev) {
switch(ev.type) {
case InputEvent::MOUSE_BUTTON: {
- Matrix32 ai = get_final_transform().affine_inverse();
+ Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y));
Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y));
ev.mouse_button.x=l.x;
@@ -781,7 +798,7 @@ void Viewport::_make_input_local(InputEvent& ev) {
} break;
case InputEvent::MOUSE_MOTION: {
- Matrix32 ai = get_final_transform().affine_inverse();
+ Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y));
Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y));
Vector2 r = ai.xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y));
@@ -795,7 +812,7 @@ void Viewport::_make_input_local(InputEvent& ev) {
} break;
case InputEvent::SCREEN_TOUCH: {
- Matrix32 ai = get_final_transform().affine_inverse();
+ Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y));
ev.screen_touch.x=t.x;
ev.screen_touch.y=t.y;
@@ -803,7 +820,7 @@ void Viewport::_make_input_local(InputEvent& ev) {
} break;
case InputEvent::SCREEN_DRAG: {
- Matrix32 ai = get_final_transform().affine_inverse();
+ Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y));
Vector2 r = ai.xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y));
Vector2 s = ai.xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y));
@@ -821,13 +838,13 @@ void Viewport::_make_input_local(InputEvent& ev) {
void Viewport::_vp_input(const InputEvent& p_ev) {
- if (render_target)
+ if (render_target && to_screen_rect==Rect2())
return; //if render target, can't get input events
//this one handles system input, p_ev are in system coordinates
//they are converted to viewport coordinates
- InputEvent ev = p_ev;
+ InputEvent ev = p_ev;
_make_input_local(ev);
input(ev);