diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2019-02-25 00:48:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 00:48:52 +0100 |
commit | 0fdcebfbb7cc6934f5a660701718ef838cbeec90 (patch) | |
tree | bd5f54f5d1ca1ec0c6c6c13fc855f0ef9b56f256 | |
parent | 21c075010660106ee15ef9ad4127342ad429f639 (diff) | |
parent | 731b152dc16ead9bb4996aa93030c82bf77da92e (diff) |
Merge pull request #26242 from serados/init_mouse_pos_win
Update Windows global mouse position at startup
-rw-r--r-- | platform/windows/os_windows.cpp | 16 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 9f15e7aad7..6e31f5b21d 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1395,6 +1395,8 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); } + update_real_mouse_position(); + return OK; } @@ -1596,6 +1598,19 @@ Point2 OS_Windows::get_mouse_position() const { return Point2(old_x, old_y); } +void OS_Windows::update_real_mouse_position() { + + POINT mouse_pos; + if (GetCursorPos(&mouse_pos) && ScreenToClient(hWnd, &mouse_pos)) { + if (mouse_pos.x > 0 && mouse_pos.y > 0 && mouse_pos.x <= video_mode.width && mouse_pos.y <= video_mode.height) { + old_x = mouse_pos.x; + old_y = mouse_pos.y; + old_invalid = false; + input->set_mouse_position(Point2i(mouse_pos.x, mouse_pos.y)); + } + } +} + int OS_Windows::get_mouse_button_state() const { return last_button_state; @@ -1738,6 +1753,7 @@ void OS_Windows::set_window_position(const Point2 &p_position) { } last_pos = p_position; + update_real_mouse_position(); } Size2 OS_Windows::get_window_size() const { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index e27dbbe530..6c257016ec 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -197,6 +197,7 @@ public: virtual void warp_mouse_position(const Point2 &p_to); virtual Point2 get_mouse_position() const; + void update_real_mouse_position(); virtual int get_mouse_button_state() const; virtual void set_window_title(const String &p_title); |