DInput: Handle mouse centering hotkey.

This commit is contained in:
Admiral H. Curtiss 2022-07-15 21:32:19 +02:00
parent 4d27022d0e
commit d57d04bb04
No known key found for this signature in database
GPG key ID: F051B4C4044F33FB

View file

@ -6,7 +6,9 @@
#include <algorithm>
#include "Common/Logging/Log.h"
#include "Core/Core.h"
#include "Core/Host.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
@ -168,13 +170,6 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device,
void KeyboardMouse::UpdateCursorInput()
{
POINT point = {};
GetCursorPos(&point);
// Get the cursor position relative to the upper left corner of the current window
// (separate or render to main)
ScreenToClient(s_hwnd, &point);
// Get the size of the current window (in my case Rect.top and Rect.left was zero).
RECT rect;
GetClientRect(s_hwnd, &rect);
@ -183,6 +178,26 @@ void KeyboardMouse::UpdateCursorInput()
const auto win_width = std::max(rect.right - rect.left, 1l);
const auto win_height = std::max(rect.bottom - rect.top, 1l);
POINT point = {};
if (g_controller_interface.IsMouseCenteringRequested() && Host_RendererHasFocus())
{
point.x = win_width / 2;
point.y = win_height / 2;
POINT screen_point = point;
ClientToScreen(s_hwnd, &screen_point);
SetCursorPos(screen_point.x, screen_point.y);
g_controller_interface.SetMouseCenteringRequested(false);
}
else
{
GetCursorPos(&point);
// Get the cursor position relative to the upper left corner of the current window
// (separate or render to main)
ScreenToClient(s_hwnd, &point);
}
const auto window_scale = g_controller_interface.GetWindowInputScale();
// Convert the cursor position to a range from -1 to 1.