summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2019-03-03 19:52:18 -0300
committerJuan Linietsky <juan@godotengine.org>2019-03-03 19:53:13 -0300
commita1e73dcc944627ab7185aec7cd4141fe4ebb97d7 (patch)
tree917b9912d48607e19d214a0e3931dd325f75d1e6 /core/os
parenta9fe834a8e962a7b9e15e5dc218af4b857b47da4 (diff)
Add support for event accumlation (off by default, on for editor), fixes #26536
Diffstat (limited to 'core/os')
-rw-r--r--core/os/input.cpp1
-rw-r--r--core/os/input.h3
-rw-r--r--core/os/input_event.cpp40
-rw-r--r--core/os/input_event.h3
4 files changed, 47 insertions, 0 deletions
diff --git a/core/os/input.cpp b/core/os/input.cpp
index cf11ba3c6d..caa9fb1493 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -91,6 +91,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW));
ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
+ ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input);
BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
diff --git a/core/os/input.h b/core/os/input.h
index b354acd961..c8b80b28d0 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -132,6 +132,9 @@ public:
virtual int get_joy_axis_index_from_string(String p_axis) = 0;
virtual void parse_input_event(const Ref<InputEvent> &p_event) = 0;
+ virtual void accumulate_input_event(const Ref<InputEvent> &p_event) = 0;
+ virtual void flush_accumulated_events() = 0;
+ virtual void set_use_accumulated_input(bool p_enable) = 0;
Input();
};
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 24ec8a1963..40308f4f7d 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -122,6 +122,8 @@ void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
+ ClassDB::bind_method(D_METHOD("accumulate", "with_event"), &InputEvent::accumulate);
+
ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
@@ -620,6 +622,44 @@ String InputEventMouseMotion::as_text() const {
return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
}
+bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
+
+ Ref<InputEventMouseMotion> motion = p_event;
+ if (motion.is_null())
+ return false;
+
+ if (is_pressed() != motion->is_pressed()) {
+ return false;
+ }
+
+ if (get_button_mask() != motion->get_button_mask()) {
+ return false;
+ }
+
+ if (get_shift() != motion->get_shift()) {
+ return false;
+ }
+
+ if (get_control() != motion->get_control()) {
+ return false;
+ }
+
+ if (get_alt() != motion->get_alt()) {
+ return false;
+ }
+
+ if (get_metakey() != motion->get_metakey()) {
+ return false;
+ }
+
+ set_position(motion->get_position());
+ set_global_position(motion->get_global_position());
+ set_speed(motion->get_speed());
+ relative += motion->get_relative();
+
+ return true;
+}
+
void InputEventMouseMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
diff --git a/core/os/input_event.h b/core/os/input_event.h
index a6a7012298..47f9293a7f 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -186,6 +186,7 @@ public:
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const;
+ virtual bool accumulate(const Ref<InputEvent> &p_event) { return false; }
InputEvent();
};
@@ -351,6 +352,8 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
+ virtual bool accumulate(const Ref<InputEvent> &p_event);
+
InputEventMouseMotion();
};