summaryrefslogtreecommitdiffstats
path: root/core/input/input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/input/input.cpp')
-rw-r--r--core/input/input.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 4e33d3087d..d87a8824f7 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -130,6 +130,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_magnetometer", "value"), &Input::set_magnetometer);
ClassDB::bind_method(D_METHOD("set_gyroscope", "value"), &Input::set_gyroscope);
ClassDB::bind_method(D_METHOD("get_last_mouse_velocity"), &Input::get_last_mouse_velocity);
+ ClassDB::bind_method(D_METHOD("get_last_mouse_screen_velocity"), &Input::get_last_mouse_screen_velocity);
ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask);
ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode);
ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode);
@@ -201,7 +202,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
Object::get_argument_options(p_function, p_idx, r_options);
}
-void Input::VelocityTrack::update(const Vector2 &p_delta_p) {
+void Input::VelocityTrack::update(const Vector2 &p_delta_p, const Vector2 &p_screen_delta_p) {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
uint32_t tdiff = tick - last_tick;
float delta_t = tdiff / 1000000.0;
@@ -210,12 +211,15 @@ void Input::VelocityTrack::update(const Vector2 &p_delta_p) {
if (delta_t > max_ref_frame) {
// First movement in a long time, reset and start again.
velocity = Vector2();
+ screen_velocity = Vector2();
accum = p_delta_p;
+ screen_accum = p_screen_delta_p;
accum_t = 0;
return;
}
accum += p_delta_p;
+ screen_accum += p_screen_delta_p;
accum_t += delta_t;
if (accum_t < min_ref_frame) {
@@ -224,6 +228,7 @@ void Input::VelocityTrack::update(const Vector2 &p_delta_p) {
}
velocity = accum / accum_t;
+ screen_velocity = screen_accum / accum_t;
accum = Vector2();
accum_t = 0;
}
@@ -594,7 +599,8 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
set_mouse_position(position);
}
Vector2 relative = mm->get_relative();
- mouse_velocity_track.update(relative);
+ Vector2 screen_relative = mm->get_relative_screen_position();
+ mouse_velocity_track.update(relative, screen_relative);
if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
Ref<InputEventScreenDrag> drag_event;
@@ -602,10 +608,12 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
drag_event->set_position(position);
drag_event->set_relative(relative);
+ drag_event->set_relative_screen_position(screen_relative);
drag_event->set_tilt(mm->get_tilt());
drag_event->set_pen_inverted(mm->get_pen_inverted());
drag_event->set_pressure(mm->get_pressure());
drag_event->set_velocity(get_last_mouse_velocity());
+ drag_event->set_screen_velocity(get_last_mouse_screen_velocity());
drag_event->set_device(InputEvent::DEVICE_ID_EMULATION);
_THREAD_SAFE_UNLOCK_
@@ -669,8 +677,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (sd.is_valid()) {
VelocityTrack &track = touch_velocity_track[sd->get_index()];
- track.update(sd->get_relative());
+ track.update(sd->get_relative(), sd->get_relative_screen_position());
sd->set_velocity(track.velocity);
+ sd->set_screen_velocity(track.screen_velocity);
if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) {
Ref<InputEventMouseMotion> motion_event;
@@ -683,7 +692,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
motion_event->set_position(sd->get_position());
motion_event->set_global_position(sd->get_position());
motion_event->set_relative(sd->get_relative());
+ motion_event->set_relative_screen_position(sd->get_relative_screen_position());
motion_event->set_velocity(sd->get_velocity());
+ motion_event->set_screen_velocity(sd->get_screen_velocity());
motion_event->set_button_mask(mouse_button_mask);
_parse_input_event_impl(motion_event, true);
@@ -827,10 +838,15 @@ Point2 Input::get_mouse_position() const {
}
Point2 Input::get_last_mouse_velocity() {
- mouse_velocity_track.update(Vector2());
+ mouse_velocity_track.update(Vector2(), Vector2());
return mouse_velocity_track.velocity;
}
+Point2 Input::get_last_mouse_screen_velocity() {
+ mouse_velocity_track.update(Vector2(), Vector2());
+ return mouse_velocity_track.screen_velocity;
+}
+
BitField<MouseButtonMask> Input::get_mouse_button_mask() const {
return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state();
}