Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Use mouse event relative motion to calculate mouse speed #56755

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,20 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
Ref<InputEventMouseMotion> mm = p_event;

if (mm.is_valid()) {
Point2 pos = mm->get_global_position();
if (mouse_pos != pos) {
set_mouse_position(pos);
Point2 position = mm->get_global_position();
if (mouse_pos != position) {
set_mouse_position(position);
}
Vector2 relative = mm->get_relative();
mouse_speed_track.update(relative);

if (main_loop && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) {
Ref<InputEventScreenDrag> drag_event;
drag_event.instance();

drag_event->set_position(mm->get_position());
drag_event->set_relative(mm->get_relative());
drag_event->set_speed(mm->get_speed());
drag_event->set_position(position);
drag_event->set_relative(relative);
drag_event->set_speed(get_last_mouse_speed());

main_loop->input_event(drag_event);
}
Expand Down Expand Up @@ -552,7 +554,6 @@ void InputDefault::set_main_loop(MainLoop *p_main_loop) {
}

void InputDefault::set_mouse_position(const Point2 &p_posf) {
mouse_speed_track.update(p_posf - mouse_pos);
mouse_pos = p_posf;
}

Expand Down
1 change: 0 additions & 1 deletion platform/javascript/os_javascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ void OS_JavaScript::mouse_move_callback(double p_x, double p_y, double p_rel_x,
ev->set_global_position(ev->get_position());

ev->set_relative(Vector2(p_rel_x, p_rel_y));
os->input->set_mouse_position(ev->get_position());
ev->set_speed(os->input->get_last_mouse_speed());

os->input->parse_input_event(ev);
Expand Down
1 change: 0 additions & 1 deletion platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ - (void)mouseMoved:(NSEvent *)event {
mm->set_relative(relativeMotion);
get_key_modifier_state([event modifierFlags], mm);

OS_OSX::singleton->input->set_mouse_position(Point2(mouse_x, mouse_y));
OS_OSX::singleton->push_input(mm);
}

Expand Down
4 changes: 0 additions & 4 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

mm->set_position(c);
mm->set_global_position(c);
input->set_mouse_position(c);
mm->set_speed(Vector2(0, 0));

if (raw->data.mouse.usFlags == MOUSE_MOVE_RELATIVE) {
Expand Down Expand Up @@ -508,7 +507,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SetCursorPos(pos.x, pos.y);
}

input->set_mouse_position(mm->get_position());
mm->set_speed(input->get_last_mouse_speed());

if (old_invalid) {
Expand Down Expand Up @@ -652,7 +650,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SetCursorPos(pos.x, pos.y);
}

input->set_mouse_position(mm->get_position());
mm->set_speed(input->get_last_mouse_speed());

if (old_invalid) {
Expand Down Expand Up @@ -754,7 +751,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SetCursorPos(pos.x, pos.y);
}

input->set_mouse_position(mm->get_position());
mm->set_speed(input->get_last_mouse_speed());

if (old_invalid) {
Expand Down
1 change: 0 additions & 1 deletion platform/x11/os_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2828,7 +2828,6 @@ void OS_X11::process_xevents() {
mm->set_button_mask(get_mouse_button_state());
mm->set_position(posi);
mm->set_global_position(posi);
input->set_mouse_position(posi);
mm->set_speed(input->get_last_mouse_speed());

mm->set_relative(rel);
Expand Down