diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/input_event.cpp | 59 | ||||
-rw-r--r-- | core/os/input_event.h | 4 |
2 files changed, 62 insertions, 1 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 2d47645a66..8c79657c64 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -199,3 +199,62 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const { return sc; } + +InputEvent InputEvent::xform_by(const Matrix32& p_xform) const { + + + InputEvent ev=*this; + + switch(ev.type) { + + case InputEvent::MOUSE_BUTTON: { + + Vector2 g = p_xform.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); + Vector2 l = p_xform.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)); + ev.mouse_button.x=l.x; + ev.mouse_button.y=l.y; + ev.mouse_button.global_x=g.x; + ev.mouse_button.global_y=g.y; + + } break; + case InputEvent::MOUSE_MOTION: { + + Vector2 g = p_xform.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); + Vector2 l = p_xform.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); + Vector2 r = p_xform.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); + Vector2 s = p_xform.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); + ev.mouse_motion.x=l.x; + ev.mouse_motion.y=l.y; + ev.mouse_motion.global_x=g.x; + ev.mouse_motion.global_y=g.y; + ev.mouse_motion.relative_x=r.x; + ev.mouse_motion.relative_y=r.y; + ev.mouse_motion.speed_x=s.x; + ev.mouse_motion.speed_y=s.y; + + } break; + case InputEvent::SCREEN_TOUCH: { + + + Vector2 t = p_xform.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)); + ev.screen_touch.x=t.x; + ev.screen_touch.y=t.y; + + } break; + case InputEvent::SCREEN_DRAG: { + + + Vector2 t = p_xform.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); + Vector2 r = p_xform.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); + Vector2 s = p_xform.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); + ev.screen_drag.x=t.x; + ev.screen_drag.y=t.y; + ev.screen_drag.relative_x=r.x; + ev.screen_drag.relative_y=r.y; + ev.screen_drag.speed_x=s.x; + ev.screen_drag.speed_y=s.y; + } break; + } + + return ev; +} diff --git a/core/os/input_event.h b/core/os/input_event.h index 0588374790..1c4f1dcf96 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -33,7 +33,7 @@ #include "typedefs.h" #include "os/copymem.h" #include "ustring.h" - +#include "math_2d.h" /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -297,6 +297,8 @@ struct InputEvent { bool is_echo() const; void set_as_action(const String& p_action, bool p_pressed); + + InputEvent xform_by(const Matrix32& p_xform) const; bool operator==(const InputEvent &p_event) const; operator String() const; InputEvent() { zeromem(this,sizeof(InputEvent)); } |