summaryrefslogtreecommitdiff
path: root/platform/windows/display_server_windows.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2020-05-08 10:56:42 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2020-05-08 10:56:42 +0300
commit78c80de738350a65980edf64a1d641b1ea3a603b (patch)
tree01b1f7b55236db0f2522039e913d6329d1139cd8 /platform/windows/display_server_windows.cpp
parente253451a5b01926a32aa52bf2e78150f0f9f4bd5 (diff)
WinTab: Adds extra "mouse move" events to make movement smoother and correctly handle pressure/tilt change when cursor is not moving.
Diffstat (limited to 'platform/windows/display_server_windows.cpp')
-rw-r--r--platform/windows/display_server_windows.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 3afe6c20ec..701cf69207 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -2015,6 +2015,61 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} else {
windows[window_id].last_tilt = Vector2();
}
+
+ POINT coords;
+ GetCursorPos(&coords);
+ ScreenToClient(windows[window_id].hWnd, &coords);
+
+ // Don't calculate relative mouse movement if we don't have focus in CAPTURED mode.
+ if (!windows[window_id].window_has_focus && mouse_mode == MOUSE_MODE_CAPTURED)
+ break;
+
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
+ mm->set_window_id(window_id);
+ mm->set_control(GetKeyState(VK_CONTROL) != 0);
+ mm->set_shift(GetKeyState(VK_SHIFT) != 0);
+ mm->set_alt(alt_mem);
+
+ mm->set_pressure(windows[window_id].last_pressure);
+ mm->set_tilt(windows[window_id].last_tilt);
+
+ mm->set_button_mask(last_button_state);
+
+ mm->set_position(Vector2(coords.x, coords.y));
+ mm->set_global_position(Vector2(coords.x, coords.y));
+
+ if (mouse_mode == MOUSE_MODE_CAPTURED) {
+ Point2i c(windows[window_id].width / 2, windows[window_id].height / 2);
+ old_x = c.x;
+ old_y = c.y;
+
+ if (mm->get_position() == c) {
+ center = c;
+ return 0;
+ }
+
+ Point2i ncenter = mm->get_position();
+ center = ncenter;
+ POINT pos = { (int)c.x, (int)c.y };
+ ClientToScreen(windows[window_id].hWnd, &pos);
+ SetCursorPos(pos.x, pos.y);
+ }
+
+ Input::get_singleton()->set_mouse_position(mm->get_position());
+ mm->set_speed(Input::get_singleton()->get_last_mouse_speed());
+
+ if (old_invalid) {
+ old_x = mm->get_position().x;
+ old_y = mm->get_position().y;
+ old_invalid = false;
+ }
+
+ mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y)));
+ old_x = mm->get_position().x;
+ old_y = mm->get_position().y;
+ if (windows[window_id].window_has_focus)
+ Input::get_singleton()->parse_input_event(mm);
}
return 0;
}