aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky2016-06-27 09:59:43 -0300
committerRémi Verschelde2016-07-08 18:34:10 +0200
commit6813c8902157c0afe37c5c7892bb83b78a623d01 (patch)
treee9c7656e612257ed3471a73fac666a510203e3b8 /core
parent406daa8f7fd3757b548f199b72f987291abdc2d0 (diff)
downloadgodot-6813c8902157c0afe37c5c7892bb83b78a623d01.tar.gz
godot-6813c8902157c0afe37c5c7892bb83b78a623d01.tar.zst
godot-6813c8902157c0afe37c5c7892bb83b78a623d01.zip
Properly deliver localized coordinates when passing gui events through parents, closes #4215
(cherry picked from commit 47d6cc08bbd745d63829e02ae408c4ce09ce1299)
Diffstat (limited to 'core')
-rw-r--r--core/os/input_event.cpp59
-rw-r--r--core/os/input_event.h4
2 files changed, 62 insertions, 1 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 2d47645a6..8c79657c6 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 058837479..1c4f1dcf9 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)); }